package command;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Usuario;

@WebServlet("/ServletLogin")
public class ServletLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		HttpSession session = request.getSession();
		session.setMaxInactiveInterval(3*60);
		
		String user = request.getParameter("usuario");
		String senha = request.getParameter("senha");
		
		Usuario usuario = new Usuario(user, senha);
		session.setAttribute("beanUsuario", usuario);
		
		if(user.equalsIgnoreCase(senha)){
			response.sendRedirect("htmls/principal.html");
		}else{
			response.sendRedirect("index.html");
			session.invalidate();
		}
	}
}